<?php

class Core_Model_DbTable_UpdateDunnageOperations extends Zend_Db_Table_Abstract {

    protected $_name = 'update_dunnage_operations';

    public function getUpdateDunnageOperation($id = -1, $offset = 0, $limit = 3) {
        if($id == -1) {
            return null;
        }

        $cond = $this->getAdapter()->quoteInto("dunnage_operation_id = (?)", $id);
        $select = $this->select()
                       ->from($this->_name)
                       ->where($cond)
                       ->limit($limit, $offset)
                       ->order("date DESC");
        
        $result = $this->fetchAll($select);
        return $result;
    }
    
    public function getUpdateDunnageOperationCols($data = NULL) {
        $fields = $this->_getDunnageOperationFields();
        if ( !empty($data) ) {
            $result = array();
            foreach ($fields as $field => $name) {
                if ( !empty($data->$field) ) {
                    $result[$field] = $name;
                }
            }
            return $result;
        }
        return $fields;
    }
    
    private function _getDunnageOperationFields() {
        return array (
            'laying_draft_paper' => 'Laying draft paper',
            'laying_plastic_sheets' => 'Laying plastic sheets', 
            'sawdust_in_frame' => 'Sawdust in frame',
            'styrofoam_in_frame' => 'Styrofoam in frame', 
            'kraft_paper_on_top' => 'Kraft paper on top', 
            'laying_bamboo_mats' => 'Laying bamboo mats',
            'laying_bamboo_sticks' => 'Laying bamboo sticks', 
            'laying_ballets' => 'Laying ballets'
        );
    }
    
    public function isEmpty($data)
    {
        $fields = $this->_getDunnageOperationFields();
        foreach (array_keys($fields) as $field)
        {
            if ( !empty($data[$field]) ) {
                return false;
            }
        }
        return true;
    }
    
    public function deleteById($id) {
        $cond = $this->getAdapter()->quoteInto("id = ?", $id);
        return $this->delete($cond);
    }
  
}

?>
